// token.js
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { userGetInfoService } from '../api/user'

export const useUserStore = defineStore('travel-user', () => {
    const token = ref('');

    const setToken = (newToken) => {
        token.value = `Bearer ${newToken}`;
    };

    const removeToken = () => {
        token.value = '';
    };

    const getToken = () => {
        return token.value;
    };
    const user = ref({})
    const getUser = async () => {
      const res = await userGetInfoService() // 请求获取数据
      user.value = res.data.data
    }
    const setUser = (obj) => {
      user.value = obj
    }
    return {
        user,
        getUser,
        setUser,
        token,
        setToken,
        removeToken,
        getToken
    };
}, {
    persist: true // 持久化存储
});